<?php

class Skjb_File
{
    public $path = null;
    
    public $directory = null;
    
    public $name = null;
    
    public $basename = null;
    
    public $extension = null;
    
    public function __construct($path)
    {
        $this->path = $path;
        $pathinfo = pathinfo($this->path);
        $this->directory = (isset($pathinfo['dirname']) ? $pathinfo['dirname'] : '');
        $this->extension = (isset($pathinfo['extension']) ? $pathinfo['extension'] : '');
        $this->basename = (isset($pathinfo['filename']) ? $pathinfo['filename'] : basename($this->path, '.' . $this->extension));
        $this->name = $pathinfo['basename'];
    }
    
    public function __toString()
    {
        return $this->path;
    }
    
    public function isDirectory()
    {
        return false;
    }
    
    public function isFile()
    {
        return true;
    }
    
    public function delete()
    {
        if (!file_exists($this->path)) {
            return false;
        }
        $delete = @unlink($this->path);
        if ($delete === false) {
            //throw new Zend_Exception('Unable to delete "' . $this->path . '"');
        }
    }
    
    public function moveToFilename($path)
    {
        rename($this->path, $path);
        $this->path = $path;
        
        return $this;
    }
    
    public function chmod($permissions = null)
    {
        @chmod($this->path, $permissions);
        
        return $this;
    }
    
    public function getContents()
    {
        return @file_get_contents($this->path);
    }
    
    public static function load($path)
    {
        return new self($path);
    }
}